package com.huawei.zyb.taskManager.domain.developer.valueobject;

import java.util.Objects;
import java.util.regex.Pattern;

/**
 * 开发者唯一标识值对象
 * 格式：字母开头 + 数字，如 Z30049429, H30023330
 */
public final class DeveloperId {
    private static final Pattern EMPLOYEE_ID_PATTERN = Pattern.compile("^[A-Z][0-9]{8,10}$");
    private final String value;

    private DeveloperId(String value) {
        if (value == null || value.trim().isEmpty()) {
            throw new IllegalArgumentException("开发者ID不能为空");
        }
        if (!EMPLOYEE_ID_PATTERN.matcher(value.trim().toUpperCase()).matches()) {
            throw new IllegalArgumentException("开发者ID格式不正确，应为字母开头+8-10位数字，如：Z30049429");
        }
        this.value = value.trim().toUpperCase();
    }

    public static DeveloperId of(String value) {
        return new DeveloperId(value);
    }

    public String getValue() {
        return value;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        DeveloperId that = (DeveloperId) obj;
        return Objects.equals(value, that.value);
    }

    @Override
    public int hashCode() {
        return Objects.hash(value);
    }

    @Override
    public String toString() {
        return "DeveloperId{" + value + "}";
    }
}